<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\RechargeRequest;
use App\CustHub\Service\RechargeService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

/**
 * 在线充值
 */
#[Controller(prefix: 'ch/recharge'),ApiAuth,VerifySignature]
class RechargeController extends BaseController
{
    #[Inject]
    protected RechargeService $service;

    public array $noNeedLogin = ['pay'];
    public array $noNeedVerifySign = ['pay'];

    /**
     * 创建充值订单
     * @param RechargeRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('createOrder')]
    public function createOrder(RechargeRequest $request): ResponseInterface
    {
        return $this->success('订单创建成功',['order_no'=>$this->service->createOrder($request->all())]);
    }

    /**
     * 订单支付
     * @param RechargeRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[RequestMapping('pay')]
    public function pay(RechargeRequest $request): ResponseInterface
    {
        return $this->success('订单支付',$this->service->pay($request->all()));
    }

    /**
     * 订单支付状态查询
     * @param RechargeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('checkPayStatus')]
    public function checkPayStatus(RechargeRequest $request): ResponseInterface
    {
        return $this->success('请求成功',['status'=>$this->service->checkPayStatus($request->all())]);
    }

}